package com.cskaoyan.javase.io._1byte._3filecopy;

import java.io.*;

/**
 * 注意使用同一个流读取文件时,上一次操作已经读取完流后,下一次操作不会从头开始读
 * @since 09:34
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Test {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("a.txt");
        FileOutputStream out1 = new FileOutputStream("b.txt");
        FileOutputStream out2 = new FileOutputStream("c.txt");
        copyFile(in, out1);
        copyFile(in, out2);
        in.close();
        out1.close();
        out2.close();
    }


    public static void copyFile(InputStream in, OutputStream out) throws IOException {
        int readCount;
        byte[] bytes = new byte[1024];
        while ((readCount = in.read(bytes)) != -1) {
            out.write(bytes, 0, readCount);
        }
    }
}
